package visual.testes;

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JScrollPane;
import java.awt.Color;
import javax.swing.JTextArea;

import servidor.varejo.ServidorVarejo;

import cliente.varejo.ClienteVarejo;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

public class frmTesteVarejo extends JFrame {
	private static final long serialVersionUID = -3592061992249421246L;
	private JPanel contentPane;
	private JTextArea JTA;

	private String nomeservico = "Encomendas";
	private String ip = "localhost";
	private int porta = 3637;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					frmTesteVarejo frame = new frmTesteVarejo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public frmTesteVarejo() {
		setTitle("Teste Varejo - RMI Atacado Varejo");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnServer = new JButton("servidor");
		btnServer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					ServidorVarejo serv = new ServidorVarejo(nomeservico, porta, JTA);
					serv.iniciar();
				} catch (RemoteException e) {
					e.printStackTrace();
				}
			}
		});
		btnServer.setFont(new Font("Dialog", Font.PLAIN, 11));
		btnServer.setBounds(10, 11, 89, 23);
		contentPane.add(btnServer);
		
		JButton btnCliente = new JButton("cliente");
//		btnCliente.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent arg0) {
//				try {
//					ClienteVarejo cli = new ClienteVarejo(ip, porta, nomeservico, JTA);
//					cli.iniciar();
//				} catch (RemoteException e) {
//					e.printStackTrace();
//				} catch (NotBoundException e) {
//					e.printStackTrace();
//				}
//			}
//		});
		btnCliente.setFont(new Font("Dialog", Font.PLAIN, 11));
		btnCliente.setBounds(109, 11, 89, 23);
		contentPane.add(btnCliente);
		
		JScrollPane scrollJTA = new JScrollPane();
		scrollJTA.setBounds(10, 45, 414, 206);
		contentPane.add(scrollJTA);
		
		JTA = new JTextArea();
		scrollJTA.setViewportView(JTA);
	}
}
